﻿Imports System.Xml.Serialization
Imports System.IO

'Créer le model dans les ressources de l'application en tant que singleton
Public Class Model
    Implements IModel

    Private _ListePMT As ListePMT

    'Liste des PMT
    ReadOnly Property ListePMT As ListePMT Implements IModel.ListePMT
        Get
            If _ListePMT Is Nothing Then
                _ListePMT = New ListePMT
            End If
            Return _ListePMT
        End Get
    End Property

    'Sérialize la collection de PMT
    Public Sub Serialize() Implements IModel.Serialize
        MsgBox("Serialization demandée")
        Dim xs As New XmlSerializer(GetType(ListePMT))
        Dim wr As New StreamWriter("Test.xml")
        With wr
            xs.Serialize(wr, Me.ListePMT)
        End With
        wr.Close()
    End Sub

    'Déserialize la collection de PMT
    Public Sub deserialize() Implements IModel.deserialize
        Dim result As ListePMT
        Dim xs As XmlSerializer = New XmlSerializer(GetType(ListePMT))
        Dim rd As New StreamReader("Test.xml")
        With rd
            result = xs.Deserialize(rd)
        End With
        _ListePMT = result
    End Sub

End Class
